# Tracing #
##Overview##
Gateway collect logs and metrics for diagnostics and performance tuning purposes. The following text provides details of what are being logged by Gateway, where to find and how to interpret them.
##Log Files##
By default, Gateway transfer log files to your *Microsoft Azure Storage* Account every 30 minutes.

* IIS Logs

	IIS Log files are transferred to container **wad-iis-logfiles**.
 
* Advanced IIS Logs 

	Advanced IIS log files are transferred to container **wad-iis-srv-adv-logs**.
	The advanced log files contain the following fields:

	### Basic Fields

	|**Field**|**Header**|**Description**|
|---|---|---|
|ContentPath|s-contentpath|Logs the URL that is the target of the action, such as http://MyServer/MyVideo.wmv. If the client was redirected, this field represents the location to which the client was redirected.|
|Client-IP|c-ip|Logs the IP address of the client that made the request.|
|Method|cs-method|Logs the HTTP method, such as **GET**, that is used in the request.|
|Server-IP|s-ip|Logs the IP address of the server on which the log file entry was generated.|
|Server Port|s-port|Logs the server port number that is configured for the service.|
|Server Name|s-computername|Logs the Internet service name and instance number that was running on the client at the time that the request was made.|
|Status|sc-status|Logs the HTTP status code.|
|Time-UTC|time|Logs the time at which the request occurred, in UTC.|
|URI-QueryString|cs-uri-query|Logs the query, if any, that the client was trying to perform. A URI query is necessary only for dynamic pages.|

	### Moudle Logging Fields

	|**Field**|**Header**|**Description**|
|---|---|---|
|BeginRequest-UTC|BeginRequest-UTC|Logs when processing of an HTTP request started, in UTC.|
|Bytes Received|cs-bytes|Logs the total number of bytes received by the client from the server. The value does not include any overhead that is added by the network stack.|
|Bytes Sent|sc-bytes|Logs the total number of bytes the server sent to the client. The value does not include any overhead that is added by the network stack. This field contains a hyphen in propagated cache/proxy logs.|
|EndRequest-UTC|EndRequest-UTC|Logs when processing of an HTTP request ended, in UTC.|

	### Performance Counter Fields
	|**Field**|**Header**|**Description**|
|---|---|---|
|CPU-Utilization|CPU-Utilization|Logs the percentage of elapsed time that the processor spends to run a non-idle thread.|
|RequestsPerSecond|RequestsPerSecond|Logs the HTTP requests/sec being processed by the worker process.|

	### Request Header Fields
	|**Field**|**Header**|**Description**|
|---|---|---|
|Cookie|cs(Cookie)|Logs the content of the cookie that is sent or received, if any.|
|Host|cs(Host)|Logs the host header name, if any.|
|UserName|cs-username|Logs the name of the authenticated user who accessed the server. Anonymous users are indicated by a hyphen.|
|User Agent|cs(User-Agent)|Logs the browser from which the request originated.|

	### Gatewy Custom Fields

	|**Field**|**Header**|**Description**|
|---|---|---|
|GW-TOTAL-RESPONSETIME|GW-TOTAL-RESPONSETIME|Total response time, including response time of external site as well as Gateway processing time.|
|GW-ARR-OVERHEAD|GW-ARR-OVERHEAD|Estimated ARR overhead, including processing time of inbound/outbound rules.|
|GW-TOTAL-OVERHEAD|GW-TOTAL-OVERHEAD|Total overhead of Gateway, including ARR processing time and Gateway processing time. |
|GW-EXTERNAL-RESPONSETIME|GW-EXTERNAL-RESPONSE|Response time of the external site.|

	> Note: GW-TOTAL-RESPONSETIME = GW-TOTAL-OVERHEAD + GW-EXTERNAL-RESPONSETIME

##Performance Counters##
By default, Gateway record the following performance counters to **WADPerformanceCountersTable** (with sample rate of 3 minutes).

* \Memory\Available MBytes
* \Web Service(_Total)\ISAPI Extension Requests/sec
* \Web Service(_Total)\Bytes Total/Sec
* \ASP.NET Applications(__Total__)\Requests/Sec
* \ASP.NET Applications(__Total__)\Errors Total/Sec
* \ASP.NET\Requests Queued
* \ASP.NET\Requests Rejected

##Other Logs##
Gateway also collects the following logs:

* Application Errors from Windows Event Log (transferred to **WADWindowsEventLogsTable**)
* Crash Dumps (transferred to **wad-crash-dumps** container)
* Microsoft Azure logs captured by the Microsoft Azure Trace Listener (applied filter: Information, transferred to **WADLogsTable**). Notification of updates available for the Service Gateway are shown in this log - see below for details.

##Log Cleanup##
Gateway automatically cleans up Advanced IIS Logs daily. Log files older than 1 day will be purged.

##Service Gateway Update Check##
As the Service Gateway operates it periodically checks if an update to the software has been published that may contain new features and/or bug fixes. If a new update is identified for the version of Service Gateway running, messages will be written to the Azure Trace logs, providing notification of the availability of an update as well as the details of that update, including the severity and a description of the changes.

Updates may be applied by a variety of means:

* The Management Console will also notify the availability of updates and manage the deployment of updates. See the [Management Console User Guide](Console) for full details.
* Latest versions of the Service Gateway source code can be fetched from http://sg.codeplex.com, built and deployed. See the [Deployment Guide](Deployment) for more information.
* The **Microsoft Azure Portal** can be used to deploy the updated package. The [Deployment Guide](Deployment) includes information for this form of deployment.

Update checks can be disabled by setting the `NoUpdateCheck` service configuration value to `True`.

  